<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            display: flex;
            list-style: none;
        }
        
        li {
            margin: 10px;
        }
        
        .active {
            background-color: pink;
        }
    </style>
</head>

<div id="app">
    {{msg}}
    <hr> 数组写法:

    <ul>
        <!-- <li :class="[active,'aa',bb]">我是第1个li</li> -->
        <!-- <li :class="{active:true,'aa':false,bb:flag}">我是第1个li</li> -->
        <li @click="itemIndex=item" v-for=" item in 4 " :class="[itemIndex==item?active:'', 'aa',bb] ">我是第{{item}}个li</li>

    </ul>
    <hr> 对象写法:
    <ul>
        <li @click="itemIndex=item" v-for=" item in 4 " :class="{active:itemIndex==item, bb:flag}">我是第{{item}}个li</li>
    </ul>
    <hr> 对象的抽离:
    <ul>
        <li @click="itemIndex=item" v-for=" item in 4 " :class="{active:itemIndex==item, ...obj}">我是第{{item}}个li</li>
    </ul>



</div>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.min.js "></script>
<script>
    const vu = new Vue({
        el: "#app ",
        data: {
            msg: 'hello vue',
            active: 'active',
            bb: 'bb',
            flag: true,
            itemIndex: 1,
            obj: {
                aa: true
            }


        },
        methods: {

        },
    })
</script>






</body>

</html>